﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kokomo.Mirror.Ia32
{
	public class Ia32Instruction
	{
		public Ia32Instruction(
			byte[] bytes,
			long offset,
			int length,
			Prefixes prefixes,
			OpCode opCode,
			Operand[] operands
			)
		{
			if (bytes == null) bytes = new byte[0];

			this.Bytes = bytes;
			this.Offset = offset;
			this.Length = length;
			this.Prefixes = prefixes;
			this.OpCode = opCode;
			this.Operands = operands;
		}

		public override string ToString()
		{
			StringBuilder builder = new StringBuilder();
			builder.AppendFormat("{0:X8}:  {1}", this.Offset, this.OpCode.Mnemonic);

			if (
				(this.Operands != null)
				&& (this.Operands.Length > 0)
				)
			{
				builder.Append(" " + string.Join(", ", (object[])this.Operands));
			}

			return builder.ToString();
		}

		public byte[] Bytes { get; private set; }
		public long Offset { get; private set; }
		public int Length { get; private set; }
		public Prefixes Prefixes { get; private set; }
		public OpCode OpCode { get; private set; }
		public Operand[] Operands { get; private set; }
	}
}
